package com.mz.ozy.activity.me;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.mz.ozy.R;
import com.mz.ozy.activity.c2c.PhotoScanActivity;
import com.mz.ozy.activity.c2c.PhotoScanNohitActivity;
import com.mz.ozy.base.BaseActivity;
import com.mz.ozy.bean.FriendBean;
import com.mz.ozy.bean.PronotionBean;
import com.mz.ozy.mvp.presenter.FriendPresenter;
import com.mz.ozy.mvp.view.FriendContract;
import com.mz.ozy.utils.glideUtils.GlideUtils;
import com.mz.ozy.widget.dialog.ImageDialog;

import org.json.JSONObject;

import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author lifeStyle on 2020/4/2 0002.
 */
public class PromotionTypeActivity extends BaseActivity<FriendContract.View, FriendPresenter> implements FriendContract.View {

    @BindView(R.id.image_click)
    ImageView imageClick;
    @BindView(R.id.btn_comit)
    Button btnComit;
    @BindView(R.id.image_logo)
    ImageView imageLogo;
    private FriendBean dataItem;
    @BindView(R.id.tv_speak)
    TextView tvSpeak;
    @BindView(R.id.tv_level_title)
    TextView tvLevelTitle;
    private FriendBean dataItem1;
    private int type;

    public static void go(Context context, int type) {
        Intent intent = new Intent(context, PromotionTypeActivity.class);
        intent.putExtra("type", type);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_promotion_type);
        ButterKnife.bind(this);
        initTitle();
        type = getIntent().getIntExtra("type", 0);
        if (type == 0) {
            tvCenterTitle.setText("晋升级别");
        } else {
            tvCenterTitle.setText("升级服务网点");
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.vipUpSh(this, type);
    }

    @OnClick({R.id.image_click, R.id.btn_comit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.image_click:
                List<String> imgList = new ArrayList<>();
                imgList.add(dataItem.getPromotion_map().getCertificate());
                PhotoScanNohitActivity.startPhotoScan(this, imgList, 0);
//                new ImageDialog(this, dataItem.getPromotion_map().getCertificate()).builder().show();
                break;
            case R.id.btn_comit:
                break;
        }
    }

    @Override
    public void getFriendSuccess(FriendBean bean) {
        dataItem1 = bean;
    }

    @Override
    public void getVipUpSuccess(JSONObject bean) {

    }

    @Override
    public void getVipUpShSuccess(FriendBean bean) {
        dataItem = bean;
        GlideUtils.loadImg(this, imageClick, bean.getPromotion_map().getCertificate());
        Drawable drawable = getResources().getDrawable(R.mipmap.promotion_comit);
        Drawable drawable1 = getResources().getDrawable(R.mipmap.promotion_comit_one);
        Drawable drawable2 = getResources().getDrawable(R.mipmap.promotion_comit_two);
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
        String levelName = "";

        if (type == 0) {
            switch (bean.getPromotion_map().getUpgrade()) {
                case 0:
                    levelName = "普通会员";
                    break;
                case 1:
                    levelName = "VIP";
                    break;
                case 2:
                    levelName = "金卡VIP";
                    break;
                case 3:
                    levelName = "钻卡VIP";
                    break;
                case 4:
                    levelName = "健康顾问";
                    break;
                case 5:
                    levelName = "资深顾问";
                    break;
                case 6:
                    levelName = "蓝宝顾问";
                    break;
                case 7:
                    levelName = "绿宝顾问";
                    break;
                case 8:
                    levelName = "红宝督导";
                    break;
                case 9:
                    levelName = "蓝钻督导";
                    break;
                case 10:
                    levelName = "绿钻督导";
                    break;
                case 11:
                    levelName = "红钻督导";
                    break;
                case 12:
                    levelName = "黑钻首席";
                    break;
            }
        } else {
            switch (bean.getPromotion_map().getUpgrade()) {
                case 1:
                    levelName = "社区服务网点";
                    break;
                case 2:
                    levelName = "区级服务网点";
                    break;
                case 3:
                    levelName = "市级服务网点";
                    break;
                case 4:
                    levelName = "地区级服务网点";
                    break;
            }
        }
        if (type == 0) {
            tvLevelTitle.setText("我的" + levelName + "结业证书");
            if (bean.getPromotion_map().getState() == 0) {
                tvSpeak.setText("您的" + levelName + "结业证书平台审核中\n请耐心等待");
                GlideUtils.loadImg(this, imageLogo, R.mipmap.promotion_comit);
                btnComit.setVisibility(View.VISIBLE);

            } else if (bean.getPromotion_map().getState() == 2) {
                btnComit.setVisibility(View.VISIBLE);
                tvSpeak.setText("您的" + levelName + "结业证书上传不正确\n请重新提交！");
                GlideUtils.loadImg(this, imageLogo, R.mipmap.promotion_comit_one);
            } else {
                btnComit.setVisibility(View.GONE);
                tvSpeak.setText("恭喜您，成功升级" + levelName + "！");
                GlideUtils.loadImg(this, imageLogo, R.mipmap.promotion_comit_two);
            }
        } else {
            tvLevelTitle.setText("我的升级证书");
            if (bean.getPromotion_map().getState() == 0) {
                tvSpeak.setText("您的证书平台审核中请耐心等待");
                GlideUtils.loadImg(this, imageLogo, R.mipmap.promotion_comit);
                btnComit.setVisibility(View.VISIBLE);

            } else if (bean.getPromotion_map().getState() == 2) {
                btnComit.setVisibility(View.VISIBLE);
                tvSpeak.setText("您的证书上传不正确请重新提交！");
                GlideUtils.loadImg(this, imageLogo, R.mipmap.promotion_comit_one);
            } else {
                btnComit.setVisibility(View.GONE);
                tvSpeak.setText("恭喜您，成功升级" + levelName + "！");
                GlideUtils.loadImg(this, imageLogo, R.mipmap.promotion_comit_two);
            }
        }
    }

    @Override
    public void getVipUpDataInfoSuccess(PronotionBean bean) {

    }

    @OnClick(R.id.btn_comit)
    public void onViewClicked() {
        if (dataItem.getPromotion_map().getState() == 0) {
            UpdataActivity.go(this, dataItem.getPromotion_map().getId(), type, false);
        } else {
            UpdataActivity.go(this, dataItem.getPromotion_map().getId(), type, true);
        }
    }
}
